home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Commodities / Watcher / Sources / Sources.lha / WatcherPrefs / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-06  |  28.3 KB  |  987 lines

  1. /****** WatcherPrefs *********************************************************
  2. *
  3. *   NAME
  4. *       WatcherPrefs -- Preferences program for Watcher (V37)
  5. *
  6. *   PURPOSE
  7. *       To set the preferences of Watcher. Watcher will automatically be
  8. *       notified when the preferences change.
  9. *
  10. *   NOTES
  11. *
  12. *   AUTHOR
  13. *       Franz Hemmer
  14. *
  15. *   SEE ALSO
  16. *
  17. ******************************************************************************
  18. *     __
  19. *  __///
  20. *  \XX/ ©1993 by Hemsoft Developments
  21. *
  22. *----------------------------------------------------------------------------
  23. *
  24. * Author:        Franz Hemmer
  25. * Written:        07.04.93
  26. * System Req.:    KS 2.04 or higher.
  27. * Notes:
  28. *
  29. */
  30.  
  31. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  32. /*                            I N C L U D E S                                    */
  33. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  34. #include <exec/types.h>                                // For UBYTE etc.
  35. #include <exec/memory.h>                            // Proto for MEMF_ANY etc.
  36. #include <clib/asl_protos.h>                        // Protos for AllocAslRequest() etc.
  37. #include <clib/dos_protos.h>                        // Protos for Lock() etc.
  38. #include <clib/exec_protos.h>                        // Protos for FindTask() etc.
  39. #include <clib/gadtools_protos.h>                // Protos for LayoutMenus() etc.
  40. #include <clib/graphics_protos.h>                // Protos for SetAPen() etc.
  41. #include <clib/intuition_protos.h>                // Protos for CloseScreen() etc.
  42. #include <dos/dos.h>                                    // For RETURN_FAIL etc.
  43. #include <dos/dosextens.h>                            // For struct Process.
  44. #include <graphics/gfxmacros.h>                    // For SetAfPt() macro.
  45. #include <intuition/intuition.h>                    // For struct EasyStruct
  46. #include <intuition/gadgetclass.h>                // For GA_Disabled.
  47. #include <libraries/gadtools.h>                    // For GTST_String
  48. #include <pragmas/asl_pragmas.h>                    // Pragmas for asl.library.
  49. #include <pragmas/dos_pragmas.h>                    // Pragmas for dos.library.
  50. #include <pragmas/exec_pragmas.h>                // Pragmas for exec.library.
  51. #include <pragmas/gadtools_pragmas.h>            // Pragmas for gadtools.library.
  52. #include <pragmas/graphics_pragmas.h>            // Pragmas for graphics.library.
  53. #include <pragmas/intuition_pragmas.h>            // Pragmas for intuition.library.
  54. #include <stdlib.h>                                    // Proto for exit().
  55. #include <string.h>                                    // Proto for strcpy ().
  56.  
  57. #include "WatcherPrefs.h"                            // GadToolsBox generated.
  58. #include "WatcherPrefs_.h"                            // Revision header.
  59. #include "/Include/Prefs.h"                        // For struct WPrefs.
  60.  
  61. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  62. /*                             D E F I N E S                                        */
  63. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  64. #define VBYTE            0                                // Defines for VolDisplayType.
  65. #define VKILOBYTE        1                                // do
  66. #define VMEGABYTE        2                                // do
  67. #define VAUTO            3                                // do
  68.  
  69. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  70. /*                             G L O B A L S                                        */
  71. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  72. UBYTE                    VersTag []    = VERSTAG;        // Version string.
  73. ULONG                    What;
  74.  
  75. /*------------*/
  76. /* Libraries: */
  77. /*------------*/
  78. struct DosLibrary    *DOSBase;                        // dos.library.
  79. struct Library        *AslBase    = NULL;                // asl.library.
  80.  
  81. /*-----------------*/
  82. /* For CLI window: */
  83. /*-----------------*/
  84. struct Process        *p                = NULL;            // Our process.
  85. struct Window        *WindowPtr    = NULL;            // CLI window.
  86.  
  87. /*--------------*/
  88. /* Preferences: */
  89. /*--------------*/
  90. struct WPrefs        *WPrefs        = NULL;            // Preference structure.
  91. struct WPrefs        *WPrefsBack    = NULL;            // Backup, so that we can restore values.
  92. BPTR                    PrefFile        = NULL;            // Preference file.
  93.  
  94. /*-------*/
  95. /* Misc: */
  96. /*-------*/
  97. UWORD chip                    WaitPointer [] =        // Designed by C=
  98. {
  99.     0x0000, 0x0000, 0x0400, 0x07C0, 0x0000, 0x07C0, 0x0100, 0x0380, 0x0000, 0x07E0,
  100.     0x07C0, 0x1FF8, 0x1FF0, 0x3FEC, 0x3FF8, 0x7FDE, 0x3FF8, 0x7FBE, 0x7FFC, 0xFF7F,
  101.     0x7EFC, 0xFFFF, 0x7FFC, 0xFFFF, 0x3FF8, 0x7FFE, 0x3FF8, 0x7FFE, 0x1FF0, 0x3FFC,
  102.     0x07C0, 0x1FF8, 0x0000, 0x07E0, 0x0000, 0x0000
  103. };
  104. struct Requester            SleepReq;                // For SleepWindow() etc.
  105.  
  106. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  107. /*                              P R O T O S                                        */
  108. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  109. void    OpenLibs                (void);
  110. void    CloseLibs            (void);
  111. void    AllocPrefs            (void);
  112. BOOL    ReadPrefs            (UBYTE *fname);
  113. BOOL    WritePrefs            (UBYTE *fname);
  114. void    ParsePrefs            (void);
  115. void    CleanExit            (UWORD ExitCode);
  116.  
  117. void    UsePrefsDefaults    (void);
  118. void    CorrectGadgets        (struct WPrefs *wprefs);
  119. BOOL    Inform                (struct Window *w, STRPTR Title, STRPTR Text, APTR args);
  120. BOOL    RequestPrefFile    (UBYTE *startdir, UBYTE *startfile, UBYTE *resultpath, UBYTE *title);
  121. void    SplitPath            (STRPTR FullPath, STRPTR PathPart, STRPTR NamePart);
  122. BOOL    SleepWindow            (struct Window *w, struct Requester *r);
  123. void    WakeUpWindow        (struct Window *w, struct Requester *r);
  124.  
  125. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  126. /*                                M A I N                                            */
  127. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  128. void main (void)
  129. {
  130.     /*-------------*/
  131.     /* L O C A L S */
  132.     /*-------------*/
  133.     BOOL GoOn = TRUE;
  134.  
  135.     /*---------*/
  136.     /* C O D E */
  137.     /*---------*/
  138.     /*-----------------------------------------------------------*/
  139.     /* Finding a pointer to our task's window for EasyRequest(). */
  140.     /*-----------------------------------------------------------*/
  141.     p = (struct Process *) FindTask (NULL);
  142.     WindowPtr = (struct Window *) p->pr_WindowPtr;
  143.  
  144.     /*-----------------*/
  145.     /* Open libraries. */
  146.     /*-----------------*/
  147.     OpenLibs ();
  148.  
  149.     /*--------------------------------------------*/
  150.     /* Allocate memory for preferences structure. */
  151.     /*--------------------------------------------*/
  152.     AllocPrefs ();
  153.  
  154.     /*-------------------------------------------------*/
  155.     /* Read the preferences before opening the window. */
  156.     /*-------------------------------------------------*/
  157.     if (!ReadPrefs ("ENV:Watcher.Prefs"))
  158.     {
  159.         if (!ReadPrefs ("ENVARC:Watcher.Prefs"))
  160.         {
  161.             if (WindowPtr)
  162.             {
  163.                 Inform (WindowPtr, "Warning", "!WARNING!\n"
  164.                                                         "Can't find Watcher preferences in the ENV:\n"
  165.                                                         "and ENVARC: directory. I'm using internal\n"
  166.                                                         "defaults.", NULL);
  167.             }
  168.             UsePrefsDefaults ();
  169.         }
  170.     }
  171.  
  172.     /*-------------------------------------------------*/
  173.     /* Copy the contents for a later possible Restore. */
  174.     /*-------------------------------------------------*/
  175.     CopyMem (WPrefs, WPrefsBack, sizeof (struct WPrefs));
  176.  
  177.     /*---------------------------------------------*/
  178.     /* Find public screen and allocate VisualInfo. */
  179.     /*---------------------------------------------*/
  180.     SetupScreen ();
  181.  
  182.     /*------------------*/
  183.     /* Open our window. */
  184.     /*------------------*/
  185.     OpenWatcherPrefsWindow ();
  186.  
  187.     /*-------------------------------------*/
  188.     /* Correct gadgets according to prefs. */
  189.     /*-------------------------------------*/
  190.     CorrectGadgets (WPrefs);
  191.  
  192.     /*-------------*/
  193.     /* IDCMP loop. */
  194.     /*-------------*/
  195.     while (GoOn)
  196.     {
  197.         Wait (1L << WatcherPrefsWnd->UserPort->mp_SigBit);
  198.         GoOn = HandleWatcherPrefsIDCMP ();
  199.     }
  200.  
  201.     /*----------------*/
  202.     /* Graceful exit. */
  203.     /*----------------*/
  204.     CleanExit (0);
  205. }
  206.  
  207. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  208. /*                              OpenLibs()                                        */
  209. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  210. void OpenLibs (void)
  211. {
  212.     /*-----------------------*/
  213.     /* Open asl.library V37. */
  214.     /*-----------------------*/
  215.     if (!(AslBase = OpenLibrary ("asl.library", 37L)))
  216.     {
  217.         CleanExit (RETURN_FAIL);
  218.     }
  219.  
  220.     /*----------------------------*/
  221.     /* Open graphics.library V37. */
  222.     /*----------------------------*/
  223.     if (!(GfxBase = (struct GfxBase *) OpenLibrary ("graphics.library", 37L)))
  224.     {
  225.         CleanExit (RETURN_FAIL);
  226.     }
  227. }
  228.  
  229. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  230. /*                              CloseLibs()                                        */
  231. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  232. void CloseLibs (void)
  233. {
  234.     if (AslBase)
  235.     {
  236.         CloseLibrary (AslBase);
  237.     }
  238.     if (GfxBase)
  239.     {
  240.         CloseLibrary ((struct Library *) GfxBase);
  241.     }
  242. }
  243.  
  244. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  245. /*                             AllocPrefs()                                        */
  246. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  247. void AllocPrefs (void)
  248. {
  249.     /*---------------------------------*/
  250.     /* Allocate memory for main prefs. */
  251.     /*---------------------------------*/
  252.     if (!(WPrefs = (struct WPrefs *) AllocVec (sizeof (struct WPrefs), MEMF_ANY | MEMF_CLEAR)))
  253.     {
  254.         exit (RETURN_FAIL);
  255.     }
  256.  
  257.     /*-------------------------------------------*/
  258.     /* Allocate memory for backup/restore prefs. */
  259.     /*-------------------------------------------*/
  260.     if (!(WPrefsBack = (struct WPrefs *) AllocVec (sizeof (struct WPrefs), MEMF_ANY | MEMF_CLEAR)))
  261.     {
  262.         exit (RETURN_FAIL);
  263.     }
  264. }
  265.  
  266. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  267. /*                              ReadPrefs()                                        */
  268. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  269. BOOL ReadPrefs (UBYTE *fname)
  270. {
  271.     /*----------------------------*/
  272.     /* Open the preferences file. */
  273.     /*----------------------------*/
  274.     if (!(PrefFile = Open (fname, MODE_OLDFILE)))
  275.     {
  276.         return (FALSE);
  277.     }
  278.  
  279.     /*---------------------------*/
  280.     /* Read the preference file. */
  281.     /*---------------------------*/
  282.     if (Read (PrefFile, WPrefs, sizeof (struct WPrefs)) != sizeof (struct WPrefs))
  283.     {
  284.         Close (PrefFile);
  285.         return (FALSE);
  286.     }
  287.  
  288.     /*----------------------------*/
  289.     /* Close the preference file. */
  290.     /*----------------------------*/
  291.     Close (PrefFile);
  292.  
  293.     return (TRUE);
  294. }
  295.  
  296. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  297. /*                             WritePrefs()                                        */
  298. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  299. BOOL WritePrefs (UBYTE *fname)
  300. {
  301.     /*-------------------------------------------------------------------*/
  302.     /* Before we write the preferences we must parse the string gadgets. */
  303.     /* This is necessary, because, then, Watcher doesn't need to figure  */
  304.     /* out how to extract the volume array from the string gadget.            */
  305.     /*-------------------------------------------------------------------*/
  306.     ParsePrefs ();
  307.  
  308.     /*----------------------------*/
  309.     /* Open the preferences file. */
  310.     /*----------------------------*/
  311.     if (!(PrefFile = Open (fname, MODE_READWRITE)))
  312.     {
  313.         return (FALSE);
  314.     }
  315.  
  316.     /*---------------------------*/
  317.     /* Read the preference file. */
  318.     /*---------------------------*/
  319.     if (Write (PrefFile, WPrefs, sizeof (struct WPrefs)) != sizeof (struct WPrefs))
  320.     {
  321.         Close (PrefFile);
  322.         Inform (WindowPtr, "Warning", "!WARNING!\n"
  323.                                                 "Error writing preferences.\n", NULL);
  324.         return (FALSE);
  325.     }
  326.  
  327.     /*----------------------------*/
  328.     /* Close the preference file. */
  329.     /*----------------------------*/
  330.     Close (PrefFile);
  331.  
  332.     return (TRUE);
  333. }
  334.  
  335. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  336. /*                             ParsePrefs()                                        */
  337. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  338. void ParsePrefs (void)
  339. {
  340.     /*-------------*/
  341.     /* L O C A L S */
  342.     /*-------------*/
  343.     UBYTE *s, scopy [20];
  344.     ULONG    SCount = 0, VCount = 0;
  345.  
  346.     /*---------*/
  347.     /* C O D E */
  348.     /*---------*/
  349.     /*-------------------------------------------------------------*/
  350.     /* First we parse wp_VolNameStrGad, and put the results in the */
  351.     /* wp_VolName [][] array.                                                    */
  352.     /*-------------------------------------------------------------*/
  353.     s = WPrefs->wp_VolNameStrGad;
  354.  
  355.     while (*s)
  356.     {
  357.         switch (*s)
  358.         {
  359.             case ':' :
  360.             {
  361.                 scopy [SCount++] = ':';                                // Copy also ':' into scopy.
  362.                 scopy [SCount] = '\0';                                // NULL terminate scopy.
  363.                 strcpy (WPrefs->wp_VolName [VCount], scopy);    // Copy volume name.
  364.                 scopy [SCount = 0] = '\0';                            // NULL scopy.
  365.                 *s++;                                                        // Advance one character.
  366.                 if (*s == '-')                                            // Check for indicator.
  367.                 {
  368.                     *s++;
  369.                     if ((*s == 'b') || (*s == 'B'))
  370.                     {
  371.                         WPrefs->wp_VolNameType [VCount] = VBYTE;
  372.                     }
  373.                     if ((*s == 'k') || (*s == 'K'))
  374.                     {
  375.                         WPrefs->wp_VolNameType [VCount] = VKILOBYTE;
  376.                     }
  377.                     if ((*s == 'm') || (*s == 'M'))
  378.                     {
  379.                         WPrefs->wp_VolNameType [VCount] = VMEGABYTE;
  380.                     }
  381.                     if ((*s == 'a') || (*s == 'A'))
  382.                     {
  383.                         WPrefs->wp_VolNameType [VCount] = VAUTO;
  384.                     }
  385.                 }
  386.                 VCount++;
  387.                 *s++;
  388.                 break;
  389.             }
  390.             case ',' :
  391.             {
  392.                 *s++;
  393.                 scopy [SCount = 0] = '\0';
  394.                 break;
  395.             }
  396.             case '-' :
  397.             {
  398.                 break;
  399.             }
  400.             default :
  401.             {
  402.                 scopy [SCount++] = *s++;
  403.                 break;
  404.             }
  405.         }
  406.     }
  407.     WPrefs->wp_VolCount = VCount;
  408.  
  409.     s = WPrefs->wp_VolAlertStrGad;
  410.  
  411.     VCount = 0;
  412.     while (*s)
  413.     {
  414.         LONG num;
  415.  
  416.         switch (*s)
  417.         {
  418.             case ':' :
  419.             {
  420.                 scopy [SCount++] = ':';                                    // Copy also ':' into scopy.
  421.                 scopy [SCount] = '\0';                                    // NULL terminate scopy.
  422.                 strcpy (WPrefs->wp_VolAlert [VCount], scopy);    // Copy volume name.
  423.                 scopy [SCount = 0] = '\0';                                // NULL scopy.
  424.                 *s++;                                                            // Advance one character.
  425.                 if (*s == '-')                                                // Check for indicator.
  426.                 {
  427.                     *s++;
  428.                     if ((*s == 'b') || (*s == 'B'))
  429.                     {
  430.                         *s++;
  431.                         num = atoi (s);
  432.                         WPrefs->wp_VolAlertLimit [VCount] = num;
  433.                         while (*s && *s != ',')
  434.                         {
  435.                             *s++;
  436.                         }
  437.                     }
  438.                     if ((*s == 'k') || (*s == 'K'))
  439.                     {
  440.                         *s++;
  441.                         num = atoi (s);
  442.                         WPrefs->wp_VolAlertLimit [VCount] = num * 1024;
  443.                         while (*s && *s != ',')
  444.                         {
  445.                             *s++;
  446.                         }
  447.                     }
  448.                     if ((*s == 'm') || (*s == 'M'))
  449.                     {
  450.                         *s++;
  451.                         num = atoi (s);
  452.                         WPrefs->wp_VolAlertLimit [VCount] = num * 1048576;
  453.                         while (*s && *s != ',')
  454.                         {
  455.                             *s++;
  456.                         }
  457.                     }
  458.                 }
  459.                 else
  460.                 {
  461.                     *s++;
  462.                 }
  463.                 VCount++;
  464.                 break;
  465.             }
  466.             case ',' :
  467.             {
  468.                 *s++;
  469.                 scopy [SCount = 0] = '\0';
  470.                 break;
  471.             }
  472.             case '-' :
  473.             {
  474.                 break;
  475.             }
  476.             default :
  477.             {
  478.                 scopy [SCount++] = *s++;
  479.                 break;
  480.             }
  481.         }
  482.     }
  483.     WPrefs->wp_VolAlertCount = VCount;
  484. }
  485.  
  486. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  487. /*                              CleanExit()                                        */
  488. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  489. void CleanExit (UWORD ExitCode)
  490. {
  491.     /*-----------------------------*/
  492.     /* User is done, we shut down. */
  493.     /*-----------------------------*/
  494.     CloseWatcherPrefsWindow ();
  495.     CloseDownScreen ();
  496.  
  497.     /*--------------------*/
  498.     /* Deallocate memory. */
  499.     /*--------------------*/
  500.     if (WPrefsBack)
  501.     {
  502.         FreeVec (WPrefsBack);
  503.     }
  504.     if (WPrefs)
  505.     {
  506.         FreeVec (WPrefs);
  507.     }
  508.  
  509.     /*------------------*/
  510.     /* Close libraries. */
  511.     /*------------------*/
  512.     CloseLibs ();
  513.     exit (ExitCode);
  514. }
  515.  
  516. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  517. /*                          UsePrefsDefaults()                                    */
  518. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  519. void UsePrefsDefaults (void)
  520. {
  521.     WPrefs->wp_PrefsIdentifier            = 87808270;
  522.     strcpy (WPrefs->wp_VolNameStrGad, "SYS:-a");
  523.     WPrefs->wp_Total                        = TRUE;
  524.     WPrefs->wp_Fast                        = FALSE;
  525.     WPrefs->wp_Chip                        = FALSE;
  526.     WPrefs->wp_Largest                    = FALSE;
  527.     WPrefs->wp_LargestFast                = FALSE;
  528.     WPrefs->wp_LargestChip                = FALSE;
  529.     WPrefs->wp_DayOfWeek                    = TRUE;
  530.     WPrefs->wp_Date                        = TRUE;
  531.     WPrefs->wp_Time                        = TRUE;
  532.     WPrefs->wp_WinLeftEdge                = 0;
  533.     WPrefs->wp_WinTopEdge                = 12;
  534.     WPrefs->wp_WinWidth                    = 640;
  535.     WPrefs->wp_UpdateSec                    = 1;
  536.     WPrefs->wp_UpdateMic                    = 0;
  537.     WPrefs->wp_NoJumpGadget                = FALSE;
  538.     WPrefs->wp_Cpu                            = FALSE;
  539.     strcpy (WPrefs->wp_PubScreen, "Workbench");
  540.     strcpy (WPrefs->wp_GuideFile, "Watcher.guide");
  541.     WPrefs->wp_VolumeFreeDirection    = FALSE;
  542.     strcpy ((UBYTE *) WPrefs->wp_VolumeFreeDirectionInd, " ^v");
  543.     strcpy ((UBYTE *) WPrefs->wp_VolAlertStrGad, "SYS:-k500");
  544.     WPrefs->wp_AppInfoAutoStart        = TRUE;
  545.     WPrefs->wp_AppInfoLeftEdge            = 0;
  546.     WPrefs->wp_AppInfoTopEdge            = 0;
  547.     strcpy (WPrefs->wp_Language, "english");
  548.     WPrefs->wp_LanguageNum                = 1;
  549.     WPrefs->wp_TimeFormat24                = TRUE;
  550.     WPrefs->wp_DateFormat                = 0;
  551. }
  552.  
  553. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  554. /*                           CorrectGadgets()                                    */
  555. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  556. void CorrectGadgets (struct WPrefs *wprefs)
  557. {
  558.     /*---------------------*/
  559.     /* Correct GD_VOLUMES: */
  560.     /*---------------------*/
  561.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_VOLUMES],
  562.                              WatcherPrefsWnd, NULL,
  563.                              GTST_String,        wprefs->wp_VolNameStrGad,
  564.                              TAG_END);
  565.  
  566.     /*-------------------*/
  567.     /* Correct GD_TOTAL: */
  568.     /*-------------------*/
  569.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_TOTAL],
  570.                              WatcherPrefsWnd, NULL,
  571.                              GTCB_Checked,        wprefs->wp_Total,
  572.                              TAG_END);
  573.  
  574.     /*------------------*/
  575.     /* Correct GD_FAST: */
  576.     /*------------------*/
  577.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_FAST],
  578.                              WatcherPrefsWnd, NULL,
  579.                              GTCB_Checked,        wprefs->wp_Fast,
  580.                              TAG_END);
  581.  
  582.     /*------------------*/
  583.     /* Correct GD_CHIP: */
  584.     /*------------------*/
  585.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_CHIP],
  586.                              WatcherPrefsWnd, NULL,
  587.                              GTCB_Checked,        wprefs->wp_Chip,
  588.                              TAG_END);
  589.  
  590.     /*---------------------*/
  591.     /* Correct GD_LARGEST: */
  592.     /*---------------------*/
  593.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_LARGEST],
  594.                              WatcherPrefsWnd, NULL,
  595.                              GTCB_Checked,        wprefs->wp_Largest,
  596.                              TAG_END);
  597.  
  598.     /*-------------------------*/
  599.     /* Correct GD_LARGESTFAST: */
  600.     /*-------------------------*/
  601.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_LARGESTFAST],
  602.                              WatcherPrefsWnd, NULL,
  603.                              GTCB_Checked,        wprefs->wp_LargestFast,
  604.                              TAG_END);
  605.  
  606.     /*-------------------------*/
  607.     /* Correct GD_LARGESTCHIP: */
  608.     /*-------------------------*/
  609.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_LARGESTCHIP],
  610.                              WatcherPrefsWnd, NULL,
  611.                              GTCB_Checked,        wprefs->wp_LargestChip,
  612.                              TAG_END);
  613.  
  614.     /*-----------------------*/
  615.     /* Correct GD_DAYOFWEEK: */
  616.     /*-----------------------*/
  617.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_DAYOFWEEK],
  618.                              WatcherPrefsWnd, NULL,
  619.                              GTCB_Checked,        wprefs->wp_DayOfWeek,
  620.                              TAG_END);
  621.  
  622.     /*------------------*/
  623.     /* Correct GD_DATE: */
  624.     /*------------------*/
  625.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_DATE],
  626.                              WatcherPrefsWnd, NULL,
  627.                              GTCB_Checked,        wprefs->wp_Date,
  628.                              TAG_END);
  629.  
  630.     /*------------------*/
  631.     /* Correct GD_TIME: */
  632.     /*------------------*/
  633.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_TIME],
  634.                              WatcherPrefsWnd, NULL,
  635.                              GTCB_Checked,        wprefs->wp_Time,
  636.                              TAG_END);
  637.  
  638.     /*-------------------------*/
  639.     /* Correct GD_WINLEFTEDGE: */
  640.     /*-------------------------*/
  641.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_WINLEFTEDGE],
  642.                              WatcherPrefsWnd, NULL,
  643.                              GTIN_Number,        wprefs->wp_WinLeftEdge,
  644.                              TAG_END);
  645.  
  646.     /*------------------------*/
  647.     /* Correct GD_WINTOPEDGE: */
  648.     /*------------------------*/
  649.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_WINTOPEDGE],
  650.                              WatcherPrefsWnd, NULL,
  651.                              GTIN_Number,        wprefs->wp_WinTopEdge,
  652.                              TAG_END);
  653.  
  654.     /*----------------------*/
  655.     /* Correct GD_WINWIDTH: */
  656.     /*----------------------*/
  657.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_WINWIDTH],
  658.                              WatcherPrefsWnd, NULL,
  659.                              GTIN_Number,        wprefs->wp_WinWidth,
  660.                              TAG_END);
  661.  
  662.     /*-----------------------*/
  663.     /* Correct GD_UPDATESEC: */
  664.     /*-----------------------*/
  665.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_UPDATESEC],
  666.                              WatcherPrefsWnd, NULL,
  667.                              GTIN_Number,        wprefs->wp_UpdateSec,
  668.                              TAG_END);
  669.  
  670.     /*-----------------------*/
  671.     /* Correct GD_UPDATEMIC: */
  672.     /*-----------------------*/
  673.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_UPDATEMIC],
  674.                              WatcherPrefsWnd, NULL,
  675.                              GTIN_Number,        wprefs->wp_UpdateMic,
  676.                              TAG_END);
  677.  
  678.     /*--------------------------*/
  679.     /* Correct GD_NOJUMPGADGET: */
  680.     /*--------------------------*/
  681.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_NOJUMPGADGET],
  682.                              WatcherPrefsWnd, NULL,
  683.                              GTCB_Checked,        wprefs->wp_NoJumpGadget,
  684.                              TAG_END);
  685.  
  686.     /*-----------------*/
  687.     /* Correct GD_CPU: */
  688.     /*-----------------*/
  689.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_CPU],
  690.                              WatcherPrefsWnd, NULL,
  691.                              GTCB_Checked,        wprefs->wp_Cpu,
  692.                              TAG_END);
  693.  
  694.     /*--------------------------*/
  695.     /* Correct GD_PUBLICSCREEN: */
  696.     /*--------------------------*/
  697.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_PUBLICSCREEN],
  698.                              WatcherPrefsWnd, NULL,
  699.                              GTST_String,        wprefs->wp_PubScreen,
  700.                              TAG_END);
  701.  
  702.     /*-----------------------*/
  703.     /* Correct GD_GUIDEFILE: */
  704.     /*-----------------------*/
  705.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_GUIDEFILE],
  706.                              WatcherPrefsWnd, NULL,
  707.                              GTST_String,        wprefs->wp_GuideFile,
  708.                              TAG_END);
  709.  
  710.     /*---------------------------------*/
  711.     /* Correct GD_VOLUMEFREEDIRECTION: */
  712.     /*---------------------------------*/
  713.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_VOLUMEFREEDIRECTION],
  714.                              WatcherPrefsWnd, NULL,
  715.                              GTCB_Checked,        wprefs->wp_VolumeFreeDirection,
  716.                              TAG_END);
  717.  
  718.     /*-------------------------------------------*/
  719.     /* Correct GD_VOLUMEFREEDIRECTIONINDICATORS: */
  720.     /*-------------------------------------------*/
  721.     if (WatcherPrefsGadgets [GD_VOLUMEFREEDIRECTION]->Flags & SELECTED)
  722.     {
  723.         WPrefs->wp_VolumeFreeDirection = TRUE;
  724.         GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_VOLUMEFREEDIRECTIONINDICATORS],
  725.                                  WatcherPrefsWnd, NULL,
  726.                                  GA_Disabled, FALSE,
  727.                                  GTST_String, wprefs->wp_VolumeFreeDirectionInd,
  728.                                  TAG_END);
  729.     }
  730.     else
  731.     {
  732.         WPrefs->wp_VolumeFreeDirection = FALSE;
  733.         GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_VOLUMEFREEDIRECTIONINDICATORS],
  734.                                  WatcherPrefsWnd, NULL,
  735.                                  GA_Disabled, TRUE,
  736.                                  GTST_String, wprefs->wp_VolumeFreeDirectionInd,
  737.                                  TAG_END);
  738.     }
  739.  
  740.     /*------------------------*/
  741.     /* Correct GD_VOLUMALERT: */
  742.     /*------------------------*/
  743.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_VOLUMALERT],
  744.                              WatcherPrefsWnd, NULL,
  745.                              GTST_String,        wprefs->wp_VolAlertStrGad,
  746.                              TAG_END);
  747.  
  748.     /*------------------------------*/
  749.     /* Correct GD_APPINFOAUTOSTART: */
  750.     /*------------------------------*/
  751.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_APPINFOAUTOSTART],
  752.                              WatcherPrefsWnd, NULL,
  753.                              GTCB_Checked,        wprefs->wp_AppInfoAutoStart,
  754.                              TAG_END);
  755.  
  756.     /*-----------------------------*/
  757.     /* Correct GD_APPINFOLEFTEDGE: */                             
  758.     /*-----------------------------*/
  759.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_APPINFOLEFTEDGE],
  760.                              WatcherPrefsWnd, NULL,
  761.                              GTIN_Number,        wprefs->wp_AppInfoLeftEdge,
  762.                              TAG_END);
  763.  
  764.     /*----------------------------*/
  765.     /* Correct GD_APPINFOTOPEDGE: */
  766.     /*----------------------------*/
  767.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_APPINFOTOPEDGE],
  768.                              WatcherPrefsWnd, NULL,
  769.                              GTIN_Number,        wprefs->wp_AppInfoTopEdge,
  770.                              TAG_END);
  771.  
  772.     /*----------------------*/
  773.     /* Correct GD_LANGAUGE: */
  774.     /*----------------------*/
  775.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_LANGUAGE],
  776.                              WatcherPrefsWnd, NULL,
  777.                              GTLV_Selected,    wprefs->wp_LanguageNum,
  778.                              TAG_END);
  779.  
  780.     /*-------------------------*/
  781.     /* Correct GD_TIME_FORMAT: */
  782.     /*-------------------------*/
  783.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_TIME_FORMAT],
  784.                              WatcherPrefsWnd, NULL,
  785.                              GTCB_Checked,        wprefs->wp_TimeFormat24,
  786.                              TAG_END);
  787.  
  788.     /*-------------------------*/
  789.     /* Correct GD_DATE_FORMAT: */
  790.     /*-------------------------*/
  791.     GT_SetGadgetAttrs (WatcherPrefsGadgets [GD_DATE_FORMAT],
  792.                              WatcherPrefsWnd, NULL,
  793.                              GTCY_Active,        wprefs->wp_DateFormat,
  794.                              TAG_END);
  795. }
  796.  
  797. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  798. /*                               Inform()                                            */
  799. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  800. BOOL Inform (struct Window *w, STRPTR Title, STRPTR Text, APTR args)
  801. {
  802.     /*-------------*/
  803.     /* L O C A L S */
  804.     /*-------------*/
  805.     struct EasyStruct es;
  806.     BOOL                    rc;
  807.  
  808.     /*---------*/
  809.     /* C O D E */
  810.     /*---------*/
  811.     SleepWindow (WatcherPrefsWnd, &SleepReq);
  812.     if (IntuitionBase)
  813.     {
  814.         /*-------------------*/
  815.         /* Build EasyStruct. */
  816.         /*-------------------*/
  817.         es.es_StructSize        = sizeof (struct EasyStruct);
  818.         es.es_Flags                = 0;
  819.         es.es_Title                = (Title) ? Title : (STRPTR) "Information";
  820.         es.es_TextFormat        = Text;
  821.         es.es_GadgetFormat    = "Okay";
  822.  
  823.         /*------------------------------------------------------*/
  824.         /* Call EasyRequestArgs() and return it's return value. */
  825.         /*------------------------------------------------------*/
  826.         rc = EasyRequestArgs (w, &es, NULL, args);
  827.         WakeUpWindow (WatcherPrefsWnd, &SleepReq);
  828.         return (rc);
  829.     }
  830.     WakeUpWindow (WatcherPrefsWnd, &SleepReq);
  831.     return (FALSE);
  832. }
  833.  
  834. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  835. /*                           RequestPrefFile()                                    */
  836. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  837. BOOL RequestPrefFile (UBYTE *startdir, UBYTE *startfile, UBYTE *resultpath, UBYTE *title)
  838. {
  839.     /*-------------*/
  840.     /* L O C A L S */
  841.     /*-------------*/
  842.     struct FileRequester    *freq    = NULL;
  843.     BOOL                        rc        = TRUE;
  844.  
  845.     /*---------*/
  846.     /* C O D E */
  847.     /*---------*/
  848.     /*--------------------------------*/
  849.     /* Make sure resultpath is empty. */
  850.     /*--------------------------------*/
  851.     resultpath [0] = '\0';
  852.  
  853.     /*-------------------------------------------*/
  854.     /* Allocating file requester for asl.library */
  855.     /*-------------------------------------------*/
  856.     if (!(freq = AllocAslRequest (ASL_FileRequest, NULL)))
  857.     {
  858.         return (FALSE);
  859.     }
  860.  
  861.     /*------------------*/
  862.     /* Requesting file. */
  863.     /*------------------*/
  864.     if (AslRequestTags (freq,
  865.                               ASLFR_Window,            (ULONG) WatcherPrefsWnd,
  866.                               ASLFR_TitleText,        title,
  867.                               ASLFR_InitialFile,        startfile,
  868.                               ASLFR_InitialDrawer,    startdir))
  869.     {
  870.         // Building TGI->gi_HighFile...
  871.         AddPart (resultpath, freq->rf_Dir, 256);
  872.         AddPart (resultpath, freq->rf_File, 256);
  873.     }
  874.     else
  875.     {
  876.         rc = FALSE;
  877.     }
  878.  
  879.     /*--------------------*/
  880.     /* Deallocate memory. */
  881.     /*--------------------*/
  882.     if (freq)
  883.     {
  884.         FreeAslRequest (freq);
  885.     }
  886.  
  887.     return (rc);
  888. }
  889.  
  890. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  891. /*                              SplitPath()                                        */
  892. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  893. void SplitPath (STRPTR FullPath, STRPTR PathPart, STRPTR NamePart)
  894. {
  895.     /*-------------*/
  896.     /* L O C A L S */
  897.     /*-------------*/
  898.     UBYTE TempBuffer [256];
  899.     UWORD    pos = 0;
  900.  
  901.     /*---------*/
  902.     /* C O D E */
  903.     /*---------*/
  904.     /*------------------------*/
  905.     /* First we split on ':'. */
  906.     /*------------------------*/
  907.     pos = SplitName (FullPath, ':', (UBYTE *) &TempBuffer [0], pos, 256);
  908.  
  909.     /*---------------------------------------------------------*/
  910.     /* Checking for ':' separator, and append it if necessary. */
  911.     /*---------------------------------------------------------*/
  912.     if (pos == -1)
  913.     {
  914.         // No separator found.
  915.         pos = 0;
  916.     }
  917.     else
  918.     {
  919.         // Separator found.
  920.         strcat (PathPart, TempBuffer);
  921.         strcat (PathPart, ":");
  922.     }
  923.  
  924.     /*-----------------------------------------------*/
  925.     /* Repeat SplitName until no more '/' are found. */
  926.     /*-----------------------------------------------*/
  927.     do
  928.     {
  929.         pos = SplitName (FullPath, '/', TempBuffer, pos, 256);
  930.         if (pos != -1)
  931.         {
  932.             strcat (PathPart, TempBuffer);
  933.             strcat (PathPart, "/");
  934.         }
  935.     } while (pos != -1);
  936.  
  937.     /*---------------------------------------------*/
  938.     /* TempBuffer now contains the file name part. */
  939.     /*---------------------------------------------*/
  940.     strcpy (NamePart, TempBuffer);
  941.     return;
  942. }
  943.  
  944. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  945. /*                             SleepWindow()                                        */
  946. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  947. BOOL SleepWindow (struct Window *w, struct Requester *r)
  948. {
  949.     /*------------------------------------------------*/
  950.     /* Initializing user supplied requster structure. */
  951.     /*------------------------------------------------*/
  952.     InitRequester (r);
  953.  
  954.     /*---------------------------------*/
  955.     /* Putting up the empty requester. */
  956.     /*---------------------------------*/
  957.     if (Request (r, w))
  958.     {
  959.         /*--------------------------------------------*/
  960.         /* Success! We also implement a busy pointer! */
  961.         /*--------------------------------------------*/
  962.         SetPointer (w, WaitPointer, 16, 16, -6, 0);
  963.         return (TRUE);
  964.     }
  965.  
  966.     /*-------------------------*/
  967.     /* Error, we return FALSE. */
  968.     /*-------------------------*/
  969.     return (FALSE);
  970. }
  971.  
  972. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  973. /*                            WakeUpWindow()                                        */
  974. /*««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*/
  975. void WakeUpWindow (struct Window *w, struct Requester *r)
  976. {
  977.     /*----------------------------*/
  978.     /* Clearing the busy pointer. */
  979.     /*----------------------------*/
  980.     ClearPointer (w);
  981.  
  982.     /*-------------------------------------------------------------------*/
  983.     /* Removing the empty requester. This reenables input in the window. */
  984.     /*-------------------------------------------------------------------*/
  985.     EndRequest (r, w);
  986. }
  987.